package com.misakyanls.examples.lists;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;

public class MergeListsBehaviour {
	@Test
	public void shouldConcatenateTwoNonIdenticalLists() {
		// Given
		List<Integer> l1 = new ArrayList<Integer>(Arrays.asList(1, 2, 3));
		List<Integer> l2 = new ArrayList<Integer>(Arrays.asList(4, 5, 6));

		// When
		List<Integer> expected = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5, 6));

		// Then
		assertThat(MergeLists.merge2(l1, l2), is(equalTo(expected)));
	}

	@Test
	public void shouldMergeTwoIdenticalLists() {
		// Given
		List<Integer> l1 = new ArrayList<Integer>(Arrays.asList(1, 2, 3));
		List<Integer> l2 = new ArrayList<Integer>(Arrays.asList(1, 2, 3));

		// When
		List<Integer> expected = new ArrayList<Integer>(Arrays.asList(1, 2, 3));

		// Then
		assertThat(MergeLists.merge2(l1, l2), is(equalTo(expected)));
	}

	@Test
	public void shouldMergeTwoListsForTime() {
		// Given
		List<Integer> l1 = new ArrayList<Integer>();
		List<Integer> l2 = new ArrayList<Integer>();
		for (int i = 0; i < 10000; i++) {
			l1.add(i);
			l2.add(i);
		}

		// When
		long startTime = System.currentTimeMillis();
		MergeLists.merge(l1, l2);
		long endTime = System.currentTimeMillis();
		System.out.println(endTime - startTime);
	}
	
	@Test
	public void shouldMergeTwoListsForTimeInOtherImplementation() {
		// Given
		List<Integer> l1 = new ArrayList<Integer>();
		List<Integer> l2 = new ArrayList<Integer>();
		for (int i = 0; i < 10000; i++) {
			l1.add(i);
			l2.add(i);
		}

		// When
		long startTime = System.currentTimeMillis();
		MergeLists.merge2(l1, l2);
		long endTime = System.currentTimeMillis();
		System.out.println(endTime - startTime);
	}


}
